using System.Collections.Generic;
using IntetfaceEditor4PDA;

namespace IntetfaceEditor4PDA
{
    public class ControlsReader
    {
        public QuerySelect query = new QuerySelect(); // Query for asking. public for testing
        /// <summary>
        /// Gets the params.
        /// </summary>
        /// <returns></returns>
        virtual public List<ParamItem> GetParams()
        {
            List<ParamItem> items;
            items = new List<ParamItem>();
            if(query.Select(SQLControlsReader.SelectParamsEdit))
            {
                LoadParamRows(items);
            }
            return items;
        }

        private void LoadParamRows(List<ParamItem> items)
        {
            List<DataRows> rows = query.GetRows();
            foreach (DataRows row in rows)
            {
                ParamItem item = new ParamItem();
                item.TableName = row.FieldByNameDef(SQLControlsReader.Light?"QRYTEXT":"TABLENAME", "");
                item.MenuText = row.FieldByName("SHEETNAME");
                item.Order = row.FieldByName("ORDERBY");
                item.IsGrid = (row.FieldByNameDef("HASGRID", "0") == "1");
                item.IDParam = int.Parse(row.FieldByName("IDSHEETINTERFACE" + (SQLControlsReader.Light?"LITE":"")));
                item.IDTopPanel = int.Parse(row.FieldByNameDef("IDTOPCONTROL", "-1"));
                item.IDParent = int.Parse(row.FieldByNameDef("IDOWNSHEET", "-1"));
                ParamItem.AddToList(items, item);
            }
        }

 
    }
}